/**
 * 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *   
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 * 
 */
package org.jiopi.ibean.kernel.remote;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

import org.jiopi.framework.ControlPanel;
import org.jiopi.framework.ModuleConsole;
import org.jiopi.ibean.kernel.NameVersion;
import org.jiopi.remote.RemoteCentralConsole;

/**
 * 
 * a Remote Module Console access gate
 * 
 * @version 0.5 2012.8.13
 * @since iBeanKernel0.5 2012.8.13
 *
 */
public class RemoteModuleConsoleImpl implements ModuleConsole {
	
	private final RemoteCentralConsole _rcc;
	
	private final NameVersion _moduleVersion;
	
	public RemoteModuleConsoleImpl(RemoteCentralConsole rcc,String moduleName,String compatibleVersion){
		this._rcc = rcc;
		_moduleVersion = new NameVersion(moduleName,compatibleVersion);
		
	}

	@Override
	public <T> T operate(String registerName, Class<T> returnType,
			Object... args) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T operateStrict(String registerName, Class<T> returnType,
			Object[] parameterTypes, Object... args) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T staticVariable(String registerName, Class<T> returnType) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> T accessControlPanel(String registerName, Class<T> returnType,Object... args) {
		InvocationHandler handler = new RemoteObject();
		if(returnType == org.jiopi.framework.ControlPanel.class){//封装远程ControlPanel对象
			return (T)new RemoteControlPanelImpl(_rcc,_moduleVersion,registerName);
		}else{
			return (T)Proxy.newProxyInstance(returnType.getClassLoader(),new Class[] { returnType },handler);
		}
	}

	@Override
	public <T> T accessControlPanelStrict(String registerName,
			Class<T> returnType, Object[] parameterTypes, Object... args) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ControlPanel accessStaticControlPanel(String registerName) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ClassLoader getClassLoader() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void refreshResource() {
		// TODO Auto-generated method stub

	}

}
